$(document).ready(function() {
    //data table
    $('#myTable1').dataTable({
        "bJQueryUI": true,
        "bPaginate": true,
        "sPaginationType": "full_numbers",
        "bFilter": true,
        "bSort": true,
        "iDisplayLength": 5,
        "aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "All"]]
    });

    $("#mark_budget").click(function() {
        if($("INPUT[name='my_budget_ids'][type='checkbox']").attr('checked')){
            $("INPUT[name='my_budget_ids'][type='checkbox']").attr('checked', false);
        }else{
            $("INPUT[name='my_budget_ids'][type='checkbox']").attr('checked', true);
        }
    });

    $("#delete_budget").click(function() {
        var cur_height = $("#bg").height();
        $("#bg").css('height',cur_height);
        var amt = $("input[name='my_budget_ids']:checked").length;
        var response = confirm('Delete all marked ? ('+amt+' item(s) marked)');
        if(response){
            $("input[name='my_budget_ids']:checked").each(function(){
                 var budget_id = $(this).val();
                 $(this).parent().parent().remove();
                 var urls = $("#link_delete_budget").text();
                 $.post(urls, {'budget_id' : budget_id} );
            });
            var setheight = cur_height - (amt * 26);
            //alert(cur_height);
            $("#bg").animate({
                height: setheight
            }, 500 );
        }
    });

});